/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Game={
    create:function () {
        volumeChange(0);
        var game={};
        var con=new PIXI.DisplayObjectContainer();
        con.interactive=true;
        // for(var i=0;i<5;i++)
        // {
        //     var page=Page1.create();
        //     con.addChild(page.ui);
        //     page.ui.y=i*pixiStageH;
        // }
        // Scroller.create(con,pixiStageW,pixiStageH,'ver',4);

        game.ui=con;

        var page0=Page0.create();
        game.ui.addChild(page0.ui);
        page0.In();


        var sc_con=new PIXI.DisplayObjectContainer();
        var arr_page=[];

        var p1=Page1.create();
        p1.ui.y=1136*0;
        sc_con.addChild(p1.ui);
        arr_page.push(p1);

        var p2=Page2.create();
        p2.ui.y=1136*1;
        arr_page.push(p2);
        sc_con.addChild(p2.ui);

        var p3=Page3.create();
        p3.ui.y=1136*2;
        arr_page.push(p3);
        sc_con.addChild(p3.ui);

        var p4=Page4.create();
        p4.ui.y=1136*3;
        arr_page.push(p4);
        sc_con.addChild(p4.ui);

        var p5=Page5.create();
        p5.ui.y=1136*4;
        arr_page.push(p5);
        sc_con.addChild(p5.ui);

        var p6=Page6.create();
        p6.ui.y=1136*5;
        arr_page.push(p6);
        sc_con.addChild(p6.ui);

        var p7=Page7.create();
        p7.ui.y=1136*6;
        arr_page.push(p7);
        sc_con.addChild(p7.ui);

        var p8=Page8.create();
        p8.ui.y=1136*7;
        arr_page.push(p8);
        sc_con.addChild(p8.ui);

        var sc=Scroller.create(sc_con,740,1136,'ver',arr_page.length-1);

        // game.ui.addChild(sc_con);
        // p1.In();

        document.addEventListener('Game_ScrollComplete',function (e) {
            arr_page[e.detail].In();
        });
        document.addEventListener('Game_ScrollStart',function (e) {
            console.log('22222')
            arr_page[e.detail].Out();
        });
        document.addEventListener('Game_PageIn',pageInHandler)

        function pageInHandler(e)
        {
            if(e.detail=='p1')
            {
                game.ui.addChildAt(sc_con,0);
                p1.In();
            }
        }


        return game;
    }

}

var ripples=[];
var rippleTarget;
function Ripple(x, y,_rippleTarget) {
    // sprite
    rippleTarget=_rippleTarget;
    this.sprite = new PIXI.Sprite(resource["assets/images/map.png"].texture);
    this.sprite.anchor.set(0.5);
    this.sprite.position.set(x, y);
    this.sprite.scale.set(0.0);
    rippleTarget.addChild(this.sprite);
    // filter
    this.filter = new PIXI.filters.DisplacementFilter(this.sprite);
}
Ripple.prototype.update = function() {

    if(this.sprite.scale.x>15)
    {
        var ripple=ripples.indexOf(this);
        ripples.splice(ripple,1);
        ripple.filter=null;
        rippleTarget.filters = ripples.map(function (element) {
            return element.filter;
        });
    }
    this.sprite.scale.x += 0.05;
    this.sprite.scale.y += 0.05;
}


var ticker=PIXI.ticker.shared;
ticker.add(function (time) {

    for(var i=0; i<ripples.length; i++) {
        ripples[i].update();
    }
});